﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using DataTransferObject.DiaryAndTrackingTask.SupportClassForUpdateTask;

namespace JSKE.DiaryAndTracking
{
    public partial class JSkePieChart : UserControl
    {
        public JSkePieChart()
        {
            InitializeComponent();
        }

        public void setData(List<PiechartItem> data)
        {
            chart1.Series[0].Points.Clear();
            chart1.Series[0].Label = "#PERCENT{P1}";
            //chart1.Legends[0].CellColumns[0].HeaderText = "Task Name";
            for (int i = 0; i < data.Count; i++)
            {
                DataPoint dtp = new DataPoint(0D, data[i].yVal);
                dtp.CustomProperties = "OriginalPointIndex="+Convert.ToString(i);
                dtp.IsValueShownAsLabel = false;
                dtp.LegendText = data[i].xVal;
                chart1.Series[0].Points.Add(dtp);
            }
            chart1.ChartAreas["Area1"].Area3DStyle.Enable3D = false;
            chart1.AntiAliasing = AntiAliasingStyles.All;
            UpdateChartSettings();
        }

        public void setMessage(String message)
        {
            textBox1.Text = message;
        }

        public void setPriorityHeaderText(String headerText)
        {
            chart1.Legends[0].CellColumns[1].HeaderText = headerText;          
            chart1.ChartAreas["Area1"].Area3DStyle.LightStyle = LightStyle.Realistic;
        }

        public void setTransperency3D(Boolean value)
        {
            //chart1.ChartAreas["Area1"].Area3DStyle.Enable3D = value;
            if (value)
            {
                chart1.Series[0].Palette = ChartColorPalette.SemiTransparent;
                cbbPallet.SelectedIndex = (int)ChartColorPalette.SemiTransparent;
            }
            else
            {
                chart1.Series[0].Palette = ChartColorPalette.None;
                cbbPallet.SelectedIndex = 0;
            }
        }
        public void setChartLablePercentLegendtxt(Boolean condition)
        {
            if (condition)
            {
                chart1.Series[0].Label = "#PERCENT{P1}(#LEGENDTEXT)";
            }
            else
            {
                chart1.Series[0].Label = "#PERCENT{P1}";
            }
        }
        public void setChart3DStyle(Boolean value)
        {
            chart1.ChartAreas["Area1"].Area3DStyle.Enable3D = value;
            checkBoxEnable3D.Checked = value;
        }

        public Chart getJskeChart()
        {
            if (chart1 == null)
            {
                InitializeComponent();
            }
            return this.chart1;
        }

        private void cbbPallet_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateChartSettings();
        }

        private void checkBoxEnable3D_CheckedChanged(object sender, EventArgs e)
        {
            UpdateChartSettings();
        }
    }
}
